import isEqual from 'lodash/isEqual';
import isFunction from 'lodash/isFunction';
import React from 'react';
import {toJS} from "mobx";
import { inject, observer } from 'mobx-react';
import { Button, Row, Col } from 'antd';
import { WeaLocaleProvider, WeaFormItem, WeaCascader, WeaInputNumber} from 'ecCom';
import {Text} from '../util/text';
const text = new Text();
const getLabel = WeaLocaleProvider.getLabel;

@observer
class WeaScore extends React.Component {

    constructor(props) {
        super(props);
        this.state = {
            values: props.values || [],
            //showUpdateScore : false
        }
    }

    // setState = (params = {}) => {
    //     Object.keys(params).forEach(o => {
    //         this.state[o] = params[o];
    //     })
    //     return this;
    // }

    onChange = (values) => {
        const {type, name, score,id,store} = this.props;
        //修改刊型和栏目时同步修改可编辑列表的data和选中记录的data
        store.datas.map((m) => {
            if(m.id == id && m.type == '1') {
                m.values[0] = values[0];
            }
            if(m.id == id && m.type == '2') {
                m.values[0] = values[0];
                m.values[1] = values[1];
            }
        });
        store.selectedDatas.map((m) => {
            if(m.id == id && m.type == '1') {
                m.values[0] = values[0];
            }
            if(m.id == id && m.type == '2') {
                m.values[0] = values[0];
                m.values[1] = values[1];
            }
        });
    }

    onChangeScore = (v) => {
        const {type, name, score,id,store} = this.props;
        //修改刊型和栏目时同步修改可编辑列表的data和选中记录的data
        store.datas.map((m) => {
            if(m.id == id) {
                m.changeScore = v;
            }
        });
        store.selectedDatas.map((m) => {
            if(m.id == id) {
                m.changeScore = v;
            }
        });
    }
    render() {
        const {store,type, name, score,id,json,values,isEdit} = this.props;
        let json1 = {
            type: 'select',
            label: getLabel(111, '刊型'),
            parent: '',
            style: { minWidth: '20%',maxWidth:'40%' },
            viewAttr: '3',
            options: [
                {
                    key: "1",
                    selected: false,
                    showname: getLabel(11, "今日政务11111111111111111111111111111111111111111111111111111111111111111111111111111")
                }, {
                    key: "2",
                    selected: false,
                    showname: getLabel(11, "绍兴信息")
                }
            ],
            subChildren: {
                "1": {
                    type: 'select',
                    label: getLabel(11, '默认得分'),
                    parent: '',
                    style: { width: 50,display:'inline-block',height:32 },
                    options: [{
                        key: "1",
                        selected: true,
                        showname: "10"
                    }],
                    viewAttr: '3'
                },
                "2": {
                    type: 'select',
                    label: getLabel(11, '默认得分'),
                    parent: '',
                    style: { width: 50,display:'inline-block',height:32 },
                    options: [{
                        key: "1",
                        selected: true,
                        showname: "10"
                    }],
                    viewAttr: '1'
                }
            }
        };

        let json2 = {
            type: 'select',
            label: getLabel(111, '刊型'),
            parent: '',
            viewAttr: '3',
            options: [
                {
                    key: "1",
                    selected: true,
                    showname: getLabel(11, "今日政务")
                }, {
                    key: "2",
                    selected: false,
                    showname: getLabel(11, "绍兴信息")
                }
            ],
            subChildren: {
                "1": {
                    type: 'select',
                    label: getLabel(11, '栏目'),
                    parent: '',
                    viewAttr: '3',
                    options: [
                        {
                            key: "1",
                            selected: true,
                            showname: getLabel(11, "今日政务栏目1")
                        }, {
                            key: "2",
                            selected: false,
                            showname: getLabel(11, "今日政务栏目2")
                        }
                    ],
                    subChildren: {
                        "1": {
                            type: 'select',
                            label: getLabel(11, '默认得分'),
                            parent: '',
                            style: { width: 50,display:'inline-block',height:32 },
                            options: [{
                                key: "1",
                                selected: true,
                                showname: "10"
                            }],
                            viewAttr: '1'
                        },
                        "2": {
                            type: 'select',
                            label: getLabel(11, '默认得分'),
                            parent: '',
                            style: { width: 50,display:'inline-block',height:32 },
                            options: [{
                                key: "1",
                                selected: true,
                                showname: "10"
                            }],
                            viewAttr: '1'
                        }
                    }
                },
                "2": {
                    type: 'select',
                    label: getLabel(11, '栏目'),
                    parent: '',
                    viewAttr: '3',
                    options: [
                        {
                            key: "1",
                            selected: true,
                            showname: getLabel(11, "绍兴信息栏目1")
                        }, {
                            key: "2",
                            selected: false,
                            showname: getLabel(11, "绍兴信息栏目2")
                        }
                    ],
                    subChildren: {
                        "1": {
                            type: 'select',
                            label: getLabel(11, '默认得分'),
                            parent: '',
                            style: { width: 50,display:'inline-block',height:32 },
                            options: [{
                                key: "1",
                                selected: true,
                                showname: "10"
                            }],
                            viewAttr: '1'
                        },
                        "2": {
                            type: 'select',
                            label: getLabel(11, '默认得分'),
                            parent: '',
                            style: { width: 50,display:'inline-block',height:32 },
                            options: [{
                                key: "1",
                                selected: true,
                                showname: "10"
                            }],
                            viewAttr: '1'
                        }
                    }
                }
            }
        };

    return (
            <div className='wea_info_score'>
                {type == '0' && <div>
                    <Row ecId={`${this && this.props && this.props.ecId || ''}_Row@xfaj3c`} style={{height:'30px',lineHeight:'30px'}}>
                        <Col ecId={`${this && this.props && this.props.ecId || ''}_Col@soo4zg`} span={3}><span className='addscore_name' title={name}>{name}</span></Col>
                        <Col ecId={`${this && this.props && this.props.ecId || ''}_Col@8cp95w`} span={16}>+{score}{text.SCORE}</Col>
                        {
                            isEdit == '1' && <Col ecId={`${this && this.props && this.props.ecId || ''}_Col@bxlna6`} span={5}><span>{text.UPDATESCORE}: </span><WeaInputNumber ecId={`${this && this.props && this.props.ecId || ''}_WeaInputNumber@igubwp`} style={{ width: '100%' }} onChange={this.onChangeScore} step={1} /></Col>
                        }
                    </Row>
                </div>}
                {type == '1' && <div>
                    <Row ecId={`${this && this.props && this.props.ecId || ''}_Row@z157w2`} style={{height:'30px',lineHeight:'30px'}}>
                        <Col ecId={`${this && this.props && this.props.ecId || ''}_Col@0bk7ei`} span={3}><span className='addscore_name' title={name}>{name}</span></Col>
                        <Col ecId={`${this && this.props && this.props.ecId || ''}_Col@3rxevm`} span={16}> <WeaCascader ecId={`${this && this.props && this.props.ecId || ''}_WeaCascader@4me7z9`} key='1'  domkey='1' compDef={json} values={values} onChange={this.onChange}/></Col>
                        {
                            isEdit == '1' && <Col ecId={`${this && this.props && this.props.ecId || ''}_Col@0ulj4g`} span={5}><span>{text.UPDATESCORE}: </span><WeaInputNumber ecId={`${this && this.props && this.props.ecId || ''}_WeaInputNumber@r2kxn2`} style={{ width: '100%' }} onChange={this.onChangeScore} step={1} /></Col>
                        }
                    </Row>
                </div>}
                {type == '2' && <div>
                    <Row ecId={`${this && this.props && this.props.ecId || ''}_Row@n9uebd`} style={{height:'30px',lineHeight:'30px'}}>
                        <Col ecId={`${this && this.props && this.props.ecId || ''}_Col@53litd`} span={3}><span className='addscore_name' title={name}>{name}</span></Col>
                        <Col ecId={`${this && this.props && this.props.ecId || ''}_Col@a9mo8l`} span={16}> <WeaCascader ecId={`${this && this.props && this.props.ecId || ''}_WeaCascader@qsp0ov`} key='1' domkey='1' compDef={json} values={values} onChange={this.onChange}/></Col>
                        {
                            isEdit == '1' && <Col ecId={`${this && this.props && this.props.ecId || ''}_Col@7lwobu`} span={5}><span>{text.UPDATESCORE}: </span><WeaInputNumber ecId={`${this && this.props && this.props.ecId || ''}_WeaInputNumber@hjg6m4`} style={{ width: '100%' }} onChange={this.onChangeScore } step={1} /></Col>
                        }
                    </Row>
                </div>}
            </div>
        );
    }
}

export {WeaScore};